<?php 

	function array_to_xml($array, $level) 
	{
		
		
        $xml = '';	   
	    $xml .= '<?xml version="1.0" encoding="ISO-8859-1"?>';
	     $xml .="\n";
	     $xml .="<listing>";
	     $xml .="\n";
	    foreach ($array as $key=>$value) 
	    {
	        //$key = strtolower($key);
	        if (is_array($value)) 
	        {
	        	
	        	//$xml .="<listing>";
	        	$xml .="\n";
	            $multi_tags = false;
	            foreach($value as $key2=>$value2) {
	                if (is_array($value2)) 
	                {
	                    $xml .= str_repeat("\t",$level)."<$key>\n";
	                    $xml .= array_to_xml($value2, $level+1);
	                    $xml .= str_repeat("\t",$level)."</$key>\n";
	                    $multi_tags = true;
	                } 
	                else 
	                {
	                    if (trim($value2)!='') 
	                    {
	                    	$value2=$value2;
	                    }
	                    else
	                    {
	                    	$value2='';
	                    }
	                        if (htmlspecialchars($value2)!=$value2) 
	                        {
	                            $xml .= str_repeat("\t",$level).
	                                    "<$key2>$value2</$key2>\n";
	                        } 
	                        else 
	                        {
	                        	$xml .= str_repeat("\t",$level).
	                                    "<$key2>$value2</$key2>\n";
	                        }
	                    
	                    $multi_tags = true;
	                }
	            }
	            if (!$multi_tags and count($value)>0)
	            {
	                $xml .= str_repeat("\t",$level)."<$key>\n";
	                $xml .= array_to_xml($value, $level+1);
	                $xml .= str_repeat("\t",$level)."</$key>\n";
	            }
	           
	            //$xml .="</listing>";
	            $xml .="\n";
	        } 
	        else 
	        {
	        	if (trim($value)=='') 
	            {
	            	$value='';
	            }
	            else
	            {
	            	$value=$value;
	            }
            	if (htmlspecialchars($value)!=$value) 
                {
                	
                    $xml .= str_repeat("\t",$level)."<$key>".
                            "<![CDATA[$value]]></$key>\n";
                } 
                else 
                {
                	
                    $xml .= str_repeat("\t",$level).
                            "<$key>$value</$key>\n";
                }
	            
	        }
	    }
	    
	    $xml .= "</listing>";
	    $xml .="\n";
	   
	    $app_path=str_replace("/", "\\", getcwd());
		
		$org_path="\\xml\\";
	    //print_r($xml);
		file_put_contents("global_to_do_category_listing_for_feed.xml",$xml);
		//file_put_contents("../../feeds/global_to_do_category_listing_for_feed.xml",$xml);
		
		
	}
	
	
	function array_to_xml_mobile_app($array, $level) 
	{
		
		
        $xml = '';	   
	    $xml .= '<?xml version="1.0" encoding="ISO-8859-1"?>';
	     $xml .="\n";
	     $xml .="<listings>";
	     $xml .="\n";
	    foreach ($array as $key=>$value) 
	    {
	        //$key = strtolower($key);
	        if (is_array($value)) 
	        {
	        	
	        	$xml .="<listing>";
	        	$xml .="\n";
	            $multi_tags = false;
	            foreach($value as $key2=>$value2) {
	                if (is_array($value2)) 
	                {
	                    $xml .= str_repeat("\t",$level)."<$key>\n";
	                    $xml .= array_to_xml($value2, $level+1);
	                    $xml .= str_repeat("\t",$level)."</$key>\n";
	                    $multi_tags = true;
	                } 
	                else 
	                {
	                    if (trim($value2)!='') 
	                    {
	                    	$value2=$value2;
	                    }
	                    else
	                    {
	                    	$value2='';
	                    }
	                        if (htmlspecialchars($value2)!=$value2) 
	                        {
	                            $xml .= str_repeat("\t",$level).
	                                    "<$key2>$value2</$key2>\n";
	                        } 
	                        else 
	                        {
	                        	$xml .= str_repeat("\t",$level).
	                                    "<$key2>$value2</$key2>\n";
	                        }
	                    
	                    $multi_tags = true;
	                }
	            }
	            if (!$multi_tags and count($value)>0)
	            {
	                $xml .= str_repeat("\t",$level)."<$key>\n";
	                $xml .= array_to_xml($value, $level+1);
	                $xml .= str_repeat("\t",$level)."</$key>\n";
	            }
	           
	            $xml .="</listing>";
	            $xml .="\n";
	        } 
	        else 
	        {
	        	if (trim($value)=='') 
	            {
	            	$value='';
	            }
	            else
	            {
	            	$value=$value;
	            }
            	if (htmlspecialchars($value)!=$value) 
                {
                	
                    $xml .= str_repeat("\t",$level)."<$key>".
                            "<![CDATA[$value]]></$key>\n";
                } 
                else 
                {
                	
                    $xml .= str_repeat("\t",$level).
                            "<$key>$value</$key>\n";
                }
	            
	        }
	    }
	    
	    $xml .= "</listings>";
	    $xml .="\n";
	   
	    $app_path=str_replace("/", "\\", getcwd());
		
		$org_path="\\xml\\";
	    
		//file_put_contents("global_to_do_category_listing_for_feed.xml",$xml);
		file_put_contents("../../feeds/global_to_do_category_listing_for_feed.xml",$xml);
		
		
	}

?>